require("./src/model/sync");
const express = require("express");
const path = require("path");
const fs = require("fs");
const https = require("https");
const bodyParser = require('body-parser');
const cors = require("cors");
const app = express();
app.use(bodyParser.urlencoded({limit: '5000mb'}));
app.use(bodyParser.json({limit: '5000mb', extended: true}));
app.use(cors());
const staticPath = path.resolve(__dirname,"./public")
app.use(express.static(staticPath));

const recordRouter = require("./src/router/api/record");
app.use("/api/record", recordRouter);

const privateCrt = fs.readFileSync(
    path.join(process.cwd(), "cert/r.cobotsys.com_bundle.crt"),
    "utf8"
  );
  const privateKey = fs.readFileSync(
    path.join(process.cwd(), "cert/r.cobotsys.com.key"),
    "utf8"
  );
  const credentials = {
    key: privateKey,
    cert: privateCrt,
  };
  
  const HTTPS_PORT = 448;
  const httpsServer = https.createServer(credentials, app);
  httpsServer.listen(HTTPS_PORT, () => {
    console.log(`HTTPS Server running on port ${HTTPS_PORT}`);
  });